
package com.ami.vmedia.gui;

import com.ami.iusb.IUSBRedirSession;
import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.gui.JVPopupMenu;
import com.ami.kvm.jviewer.gui.LocaleStrings;
import com.ami.vmedia.RedirectionController;
import com.ami.vmedia.VMApp;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTable;
import javax.swing.table.TableModel;

public class StatusTable {
	private final int TABLE_ROWS = 4;
	private final String DISCONNECT = "Disconnect";
	private Object[] tableData;
	private String[][] tableStringData;
	private int numInstnces;
	private int deviceType;
	private int deviceIndex;
	private String[] columnNames = { LocaleStrings.getString("AL_1_ST"), LocaleStrings.getString("AL_2_ST"),
			LocaleStrings.getString("AL_3_ST"), LocaleStrings.getString("AL_4_ST") };

	private JTable statusTable;

	private JVPopupMenu popupMenu;

	public StatusTable(int paramInt) {
		this.tableData = new Object[4];
		switch (paramInt) {
		case 0:
			this.tableData[0] = LocaleStrings.getString("AJ_1_DCP");
			this.tableData[1] = LocaleStrings.getString("AL_8_ST");
			this.tableData[2] = LocaleStrings.getString("AL_8_ST");
			this.tableData[3] = LocaleStrings.getString("AL_8_ST");
			this.numInstnces = VMApp.getInstance().getNumCD();
			break;
		case 1:
			this.tableData[0] = LocaleStrings.getString("AJ_2_DCP");
			this.tableData[1] = LocaleStrings.getString("AL_8_ST");
			this.tableData[2] = LocaleStrings.getString("AL_8_ST");
			this.tableData[3] = LocaleStrings.getString("AL_8_ST");
			this.numInstnces = VMApp.getInstance().getNumFD();
			break;
		case 2:
			this.tableData[0] = LocaleStrings.getString("AJ_3_DCP");
			this.tableData[1] = LocaleStrings.getString("AL_8_ST");
			this.tableData[2] = LocaleStrings.getString("AL_8_ST");
			this.tableData[3] = LocaleStrings.getString("AL_8_ST");
			this.numInstnces = VMApp.getInstance().getNumHD();
		}

		this.tableStringData = new String[this.numInstnces][4];

		for (int i = 0; i < this.numInstnces; i++) {
			for (int j = 0; j < 4; j++) {
				if (j == 0) {
					String str = (String) this.tableData[0];
					this.tableStringData[i][j] = str;
					this.tableStringData[i][j] = this.tableStringData[i][j].concat(" " + (i + 1));
				} else {
					this.tableStringData[i][j] = ((String) this.tableData[j]);
				}
			}
		}

		this.statusTable = new JTable(this.tableStringData, this.columnNames) {
			private static final long serialVersionUID = 1L;

			public boolean isCellEditable(int paramAnonymousInt1, int paramAnonymousInt2) {
				return false;
			}

		};
		this.statusTable.addMouseListener(new StatusTableMouseListener());
		this.statusTable.setShowGrid(false);
		this.statusTable.setSelectionMode(0);
		this.statusTable.setCellSelectionEnabled(false);
		this.statusTable.setRowSelectionAllowed(true);
		this.statusTable.setCellEditor(null);
		this.statusTable.setEnabled(true);
		initPopupMenu();
	}

	public JTable getStatusTable() {
		return this.statusTable;
	}

	private void initPopupMenu() {
		this.popupMenu = new JVPopupMenu();
		this.popupMenu.addMenuItem(LocaleStrings.getString("AJ_5_DCP"), "Disconnect", ' ', null);
		this.popupMenu.addActionListener(new StatusTablePopupActionListener());
	}

	private class StatusTableMouseListener extends MouseAdapter {
		private StatusTableMouseListener() {
		}

		public void mouseReleased(MouseEvent paramMouseEvent) {
			JTable localJTable = (JTable) paramMouseEvent.getComponent();
			StatusTable.this.deviceIndex = localJTable.getSelectedRow();
			if (paramMouseEvent.isPopupTrigger()) {
				if (localJTable.getSelectedRow() < 0) {
					return;
				}
				String str = (String) localJTable.getModel().getValueAt(localJTable.getSelectedRow(), 0);
				str = str.substring(0, str.indexOf(": ") + 2);

				if (str.equals(LocaleStrings.getString("AJ_1_DCP"))) {
					StatusTable.this.deviceType = 0;

				} else if (str.equals(LocaleStrings.getString("AJ_2_DCP"))) {
					StatusTable.this.deviceType = 1;

				} else if (str.equals(LocaleStrings.getString("AJ_3_DCP"))) {
					StatusTable.this.deviceType = 2;
				} else {
					Debug.out.println("Wrong Device Label : " + str);
					return;
				}

				if (VMApp.getInstance().getIUSBRedirSession().getDeviceRedirStatus(StatusTable.this.deviceType,
						StatusTable.this.deviceIndex) == 1) {
					StatusTable.this.popupMenu.show(localJTable, paramMouseEvent.getX(), paramMouseEvent.getY());
				}
			}
		}
	}

	private class StatusTablePopupActionListener implements ActionListener {
		private StatusTablePopupActionListener() {
		}

		public void actionPerformed(ActionEvent paramActionEvent) {
			if (paramActionEvent.getActionCommand().equals("Disconnect")) {
				VMApp.getInstance().getRedirectionController().handleDeviceRedirection(StatusTable.this.deviceType,
						StatusTable.this.deviceIndex);
			}
		}
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\vmedia\gui\StatusTable.class
 * Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */